package com.etc;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

public class TestMain {

    public static void main(String[] args) {

        Student stu = new Student();
        stu.setSname("aaa");
        stu.setAge(6);

        // TODO 验证工具类
        check(stu);

    }

    private static void check(Student stu) {

        Class c1 = stu.getClass(); // Student.class中信息

        // 所有的属性数组
        Field[] fs = c1.getDeclaredFields();

        for (Field item: fs) {

            Annotation[] an = item.getDeclaredAnnotations();
            for (Annotation item1: an) {
                if (item1 instanceof CheckAge) { // instanceof
                    CheckAge ca = (CheckAge)item1;
                    if (stu.getAge() < ca.min()) {
                        System.out.println(ca.message());
                    }
                }
            }
        }
    }
}
